import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()
driver.maximize_window()

driver.get("https://www.baidu.com")
# ele = driver.find_element(By.XPATH, "//input[@id='su']")
# 鼠标右键点击
# ActionChains(driver).context_click(ele).perform()
# 鼠标双击
# ActionChains(driver).double_click(ele).perform()
# 鼠标悬停
ele = driver.find_element(By.XPATH, "//span[text()='设置']")
ActionChains(driver).move_to_element(ele).perform()
time.sleep(2)
driver.find_element(By.XPATH, "//span[text()='搜索设置']").click()
time.sleep(1)
driver.find_element(By.XPATH, "//a[text()='保存设置']").click()
time.sleep(2)
print(driver.switch_to.alert.text)
time.sleep(2)
driver.switch_to.alert.accept()
# driver.switch_to.alert.dismiss()

# ele = driver.find_element(By.XPATH, "//input[@id='kw']")
# # 输入python
# ele.send_keys("python")
# time.sleep(2)
# # 按一下删除
# ele.send_keys(Keys.BACK_SPACE)
# time.sleep(2)
# # 按一下删除
# ele.send_keys(Keys.BACK_SPACE)
# time.sleep(2)
# # ctrl+a全选
# ele.send_keys(Keys.CONTROL, 'a')
# time.sleep(2)
# # ctrl+c复制
# ele.send_keys(Keys.CONTROL, 'c')
# time.sleep(2)
# # ctrl+v粘贴
# for i in range(5):
#     ele.send_keys(Keys.CONTROL, 'v')
#     time.sleep(1)

time.sleep(5)
driver.quit()